package com.yunxi.controller.sto;

import com.yunxi.sto.pojo.FinanceCompanyVO;
import com.yunxi.sto.service.FinanceCompanyDubboService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yunxi.core.web.ResponseUtil;
import java.util.*;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.LoginInfo;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 融资机构 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-09-11
 */
@RestController
@RequestMapping("/admin/financeCompany")
@Api(tags = "sto:financeCompany", description = "融资机构接口")
public class FinanceCompanyController {
    private static final Logger logger = LoggerFactory.getLogger(FinanceCompanyController.class);

    @Autowired
    FinanceCompanyDubboService financeCompanyDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询融资机构分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(FinanceCompanyVO financeCompanyVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(financeCompanyDubboService.findPageByVO(financeCompanyVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询融资机构列表")
    public ApiResult list(FinanceCompanyVO financeCompanyVO) throws Exception {
        return ResponseUtil.ok(financeCompanyDubboService.listByVo(financeCompanyVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个融资机构")
    @ApiImplicitParam(paramType="query", name = "companyId", value = "主键id", required = true, dataType = "String")
    public ApiResult load(String companyId) throws Exception {
        return ResponseUtil.ok(financeCompanyDubboService.getById(companyId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存融资机构信息")
    public ApiResult save(@RequestBody FinanceCompanyVO financeCompanyVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        financeCompanyDubboService.saveOrUpdate(financeCompanyVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除融资机构")
    public ApiResult del(@RequestBody List<String> list) throws Exception {
        financeCompanyDubboService.delAndReset(list,1);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/reset")
    @ApiOperation(value = "恢复融资机构")
    public ApiResult reset(@RequestBody List<String> list) throws Exception {
        financeCompanyDubboService.delAndReset(list,0);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/financeList")
    @ApiOperation(value = "金融机构列表")
    public ApiResult financeList() throws Exception {
        return ResponseUtil.ok(financeCompanyDubboService.financeList());
    }

}
